package com.cloudptt.api.product.func.call.group.fsm.video;

import com.cloudptt.api.comm.CauseCont;
import com.cloudptt.api.models.call.RtcpMsg;
import com.cloudptt.api.product.func.call.CallConst;
import com.cloudptt.api.product.func.call.group.fsm.call.GroupCallAgent;
import com.cloudptt.api.product.func.call.group.fsm.floor.ISubState;
import com.cloudptt.api.product.log.Log;
import com.mcptt.db.model.AddrInfo;


public class VideoPermissionState implements ISubState
{
	private VideoAgent agent = null;

	public VideoPermissionState(VideoAgent agent)
	{
		this.agent = agent;
		Log.d(GroupCallAgent.Log_Key, "currentState is VideoPermissionState");
		
		this.agent.opAudioMedia(1);
		this.agent.opVideoMedia(1);
	}
	public int doUserAction(int btnAction)
	{
		int result = CauseCont.OperateCheck_Suc;
		if(CallConst.BtnAction_Release == btnAction)
		{
			result = agent.transRelease();
			agent.goToState(CallConst.VideoState_PendingRelease);
		}
		return result;
	}
	@Override
	public void receiveRtcpMsg(RtcpMsg msg) {
		// TODO Auto-generated method stub
		Log.d(GroupCallAgent.Log_Key, "" + CallConst.stateTag(getState()) + " receiveRtcpMsg msg = " + msg);
		if(msg == null)
		{
			return;
		}

		String title = msg.getTitle();
		if(title.equals(RtcpMsg.Title_MCV1_REVOKED))
		{
			int cause = msg.getCause();
			Log.d(GroupCallAgent.Log_Key, "" + CallConst.stateTag(getState()) + " receiveRtcpMsg cause = " + cause);
			int result =  agent.transRelease();
			if(result == CallConst.Operate_Suc)
			{
				agent.goToState( CallConst.VideoState_PendingRelease);
			}
		}
		else if(title.equals(RtcpMsg.Title_MCV1_GRANTED))
		{
		}
	}
	public void updateTakenUser(String CallType,AddrInfo gInfo,AddrInfo user)
	{}
	public void destory()
	{
		this.agent.opAudioMedia(0);
		this.agent.opVideoMedia(0);
		agent = null;
	}
	
	@Override
	public int getState() {
		// TODO Auto-generated method stub
		return CallConst.VideoState_Permission;
	}
}
